package com.lesent.hadoop.domain;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author shengtao
 * @Description: 订单号
 * @date 2018/12/29 10:31
 */
public class OrderBean implements WritableComparable<OrderBean> {

    private Text itermId;

    private DoubleWritable amount;

    public OrderBean() {
    }

    public OrderBean(Text itermId, DoubleWritable amount) {
        this.itermId = itermId;
        this.amount = amount;
    }

    public Text getItermId() {
        return itermId;
    }

    public void setItermId(Text itermId) {
        this.itermId = itermId;
    }

    public DoubleWritable getAmount() {
        return amount;
    }

    public void setAmount(DoubleWritable amount) {
        this.amount = amount;
    }

    @Override
    public int compareTo(OrderBean o) {
        int resu = this.itermId.compareTo(o.itermId);
        if(resu == 0){
            resu = this.amount.compareTo(o.getAmount());
        }
        return resu;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(itermId.toString());
        dataOutput.writeDouble(amount.get());
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.itermId = new Text(dataInput.readUTF());
        this.amount = new DoubleWritable(dataInput.readDouble());
    }

    @Override
    public String toString() {
        return "OrderBean{" +
                "itermId=" + itermId.toString() +
                ", amount=" + amount.get() +
                '}';
    }
}
